<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
	<jsp:include page="../base.jsp"></jsp:include>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css" media="all">
<script src="${ctx}/static/layui/layui.js"></script>
<script type="text/javascript" src="${ctx}/static/zTree_v3/js/jquery-1.4.4.min.js"></script>
<link rel="stylesheet" href="${ctx}/static/css/font.css">
<link rel="stylesheet" href="${ctx}/static/css/weadmin.css" media="all">
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend style="margin-left:42%;">权限信息</legend>
</fieldset>
<form class="layui-form" action="" lay-filter="forms" style="margin-left:10px;margin-right:50px;">
<input hidden="true" name="parentId" value="${parentId}">
<input hidden="true" name="id" value="${permission.id}">
<input hidden="true" name="type" value="${type}">

  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">权限名称</label>
      <div class="layui-input-inline">
        <input type="tel" name="name" value="${permission.name}" lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入权限名称">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">权限标识</label>
      <div class="layui-input-inline">
        <input type="text" name="permission" value="${permission.permission}" lay-verify="required" autocomplete="off" class="layui-input" placeholder="例如 user:list">
      </div>
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">菜单url</label>
    <div class="layui-input-block">
      <input type="text" name="resUrl" value="${permission.resUrl}" lay-verify="required" autocomplete="off" placeholder="请输入url" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">排序</label>
    <div class="layui-input-block">
      <input type="text" name="sort" value="${permission.sort}" lay-verify="required|number" placeholder="1,2,3....." autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">操作类型</label>
    <div class="layui-input-block">
      <input type="checkbox" lay-skin="primary" title="目录"
      	<c:if test="${type eq '0'}">
      		checked="true"
      	</c:if>
       disabled="">
      <input type="checkbox" lay-skin="primary" title="菜单" 
      	<c:if test="${type eq '1'}">
      		checked="true"
      	</c:if>
       disabled="">
      <input type="checkbox" lay-skin="primary" title="按钮" 
      	<c:if test="${type eq '2'}">
      		checked="true"
      	</c:if>
      disabled="">
    </div>
  </div>
  <div class="layui-form-item" style="margin-top:35px;">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="permissionSave">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
 </body>
<script type="text/javascript">
layui.use(['form', 'layedit'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  
  //自定义验证规则
  form.verify({
	  userName: function(value){
      if(value.length > 6){
        return '不得多于6个字符';
      }
      if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
          return '权限名称不能有特殊字符';
        }
        if(/(^\_)|(\__)|(\_+$)/.test(value)){
          return '权限名称首尾不能出现下划线\'_\'';
        }
    },
    resUrl: function(value){
         if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
             return '菜单url不能有特殊字符';
           }
       }
  });
  
  //监听提交
   form.on('submit(permissionSave)', function(data){
	  var formDatas = data.field;
	  formDatas.parentId=parseInt(formDatas.parentId);
	  formDatas.sort=parseInt(formDatas.sort);
	  var url = "${ctx}/admin/permission/save";
            $.post(url,formDatas,function(result){
				if(!result.msg){
					layer.msg("没有权限访问", {icon: 2});
					return
				}
				layer.msg(result.msg, {icon: 1});
				if(result.status){ //为真刷新表格
					setTimeout(function(){
						window.parent.location.reload();
						window.parent.layer.closeAll();
					}, 1000 )
				}
            });

	return false;
  }); 
});
</script>
</html>